<template>
    <div>
      <!--  面包屑  -->
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>订单管理</el-breadcrumb-item>
        <el-breadcrumb-item>订单列表</el-breadcrumb-item>
      </el-breadcrumb>
      <!--  卡片  -->
      <el-card>
        <el-row :gutter="20">
          <el-col :span="8">
            <!--   搜索添加   -->
            <el-input
                      clearable
                      placeholder="请输入内容"
                      class="input-with-select">
              <el-button
                         slot="append"
                         icon="el-icon-search"></el-button>
            </el-input>
          </el-col>
        </el-row>
        <div style="width: 10px"></div>
        <!--   订单列表   -->
        <el-table
          border
          stripe
          :data="orderList"
          style="width: 100%">
          <el-table-column
            align="center"
            type="index">
          </el-table-column>
          <el-table-column
            prop="order_number"
            align="center"
            label="订单编号">
          </el-table-column>
          <el-table-column
            prop="order_price"
            align="center"
            label="订单价格">
          </el-table-column>
          <el-table-column
            align="center"
            label="是否付款">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.order_pay === '1'"
                      type="success">已付款</el-tag>
              <el-tag v-else
                      type="danger">未付款</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            prop="is_send"
            align="center"
            label="是否发货">
          </el-table-column>
          <el-table-column
            align="center"
            label="下单时间">
            <template slot-scope="scope">
              {{scope.row.create_time | dataFromTime}}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="操作">
            <template slot-scope="scope">
              <el-button
                         @click="openAdder"
                         type="primary"
                         icon="el-icon-edit"
                         size="small"></el-button>
              <el-button
                         type="success"
                         @click="logistics"
                         icon="el-icon-location"
                         size="small"></el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--   分页   -->
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-card>
      <!--  修改地址对话框  -->
      <el-dialog
        @close="addressClosed"
        title="修改地址"
        :visible.sync="updateAddress"
        width="50%">
        <!--   主体区域   -->
        <el-form :model="updateFromAddress"
                 :rules="updateAddressRules"
                 ref="updateAddressRef"
                 label-width="100px">
          <el-form-item label="省市区县" prop="district">
            <el-cascader
              expand-trigger="hover"
              v-model="updateFromAddress.district"
              change-on-select
              clearable
              :options="cityData">
            </el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="address">
            <el-input v-model="updateFromAddress.address"></el-input>
          </el-form-item>
        </el-form>
        <!--   按钮区域   -->
        <span slot="footer"
              class="dialog-footer">
        <el-button @click="updateAddress = false">取 消</el-button>
        <el-button type="primary"
                   @click="updateAddress = false">确 定</el-button>
      </span>
      </el-dialog>
      <!--  物流对话框  -->
      <el-dialog
        title="物流进度"
        :visible.sync="btnlogistics"
        width="50%">
        <!--   主体区域   -->
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in logisticsData"
            :key="index"
            :timestamp="activity.time"
            placement="top">
            <el-card>
              <p :title="activity.context">{{activity.context}}</p>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </el-dialog>
    </div>
</template>

<script>
    import citydata from "../../assets/citydata";
    export default {
        name: "Order",
        data(){
            return{
                logisticsData:[],
                btnlogistics:false,
                cityData:citydata,
                setparamsList: [],
                updateAddressRules:{
                    address:[
                        {
                            required: true, message: '请输入详细地址', trigger: 'blur'
                        }
                    ],
                    district:[
                        {
                            required: true, message: '请选择省市区县', trigger: 'blur'
                        }
                    ]
                },
                updateFromAddress:{
                    district:[],
                    address:''
                },
                updateAddress:false,
                orderList:[],
                total:0,
                queryInfo: {
                    query: '',
                    // 当前页数
                    pagenum: 1,
                    // 当前显示多少条数据
                    pagesize: 10
                }
            }
        },
        mounted() {
          this.setOrders()
        },
        methods:{
            // 订单列表
            setOrders(){
                this.$http.get('orders',{
                    params: this.queryInfo
                }).then(res => {
                    if (res.data.meta.status !== 200) {
                        return this.$message.error(res.data.meta.msg)
                    }
                    this.orderList = res.data.data.goods
                    this.total = res.data.data.total
                })
            },
            // 最新页码数
            handleSizeChange (newSize) {
                this.queryInfo.pagesize = newSize
                this.setOrders()
            },
            // 监听页码
            handleCurrentChange (newPage) {
                console.log(newPage)
                this.queryInfo.pagenum = newPage
                this.setOrders()
            },
            // 修改地址
            openAdder(){
                this.updateAddress = true
            },
            // 重置
            addressClosed(){
                this.$refs.updateAddressRef.resetFields()
            },
            // 物流
            logistics(){
                this.$http.get('/kuaidi/804909574412544580').then(res => {
                    if (res.data.meta.status !== 200) {
                        return this.$message.error(res.data.meta.msg)
                    }
                    this.logisticsData = res.data.data
                    this.btnlogistics = true
                })
            }
        }
    }
</script>

<style lang="less" scoped>

</style>
